package com.cg.controller;

import com.cg.dto.OrderPageDto;
import com.cg.dto.PayDto;
import com.cg.dto.Result;
import com.cg.dto.ResultUtils;
import com.cg.service.OrderService;
import com.cg.vo.OrderListVo;
import com.cg.vo.PatientOrderVo;
import com.cg.vo.PayOrderVo;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * (Order)表控制层
 *
 * @author chengong
 * @since 2024-01-14 17:00:58
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    /**
     * 服务对象
     */
    @Resource
    private OrderService orderService;

    /**
     * 预约信息列表
     */
    @PostMapping("/queryOrderList")
    public Result<Map<String,Object>> queryOrderList(@RequestBody OrderPageDto orderPageDto){
        Map<String ,Object> map = new HashMap<>();
        PageInfo<OrderListVo> pageInfo = orderService.queryOrderList(orderPageDto);
        map.put("pageInfo",pageInfo);
        return ResultUtils.returnDataSuccess(map);
    }


    /**
     * 获取患者信息及其预约信息
     */
    @PostMapping("/queryPatientOrder")
    public Result<PatientOrderVo> queryPatientOrder(@RequestBody OrderPageDto orderPageDto){
        return orderService.queryPatientOrder(orderPageDto);
    }


    /**
     * 取号前查询订单支付方式
     */
    @GetMapping("/getPayOrderByOrderNum")
    public Result<PayOrderVo> getPayOrderByOrderNum(@RequestParam("orderNum") String orderNum){
        return ResultUtils.returnDataSuccess(orderService.getPayOrderByOrderNum(orderNum));
    }

    /**
     * 去支付
     */
    @PostMapping("/toPay")
    public Result<String> toPay(@RequestBody PayDto payDto){
        return orderService.toPay(payDto);
    }
}

